home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 6 / MacMania 6.toast / / Multimedia & Desktop / VideoToolbox / VideoToolboxSources / VideoToolbox.h < prev    next >
Text File  |  1997-05-30  |  52KB  |  1,435 lines

  1. /*
  2. VideoToolbox.h
  3. This file contains the necessary prototypes for use of all the VideoToolbox
  4. files except Luminance.c, which has its own header file, Luminance.h, and
  5. GDInfo.c and GDTestClut.c, which use GDInfo.h.
  6.  
  7. Precompilation of this header, producing VideoToolbox????.pre, 
  8. will reduce your compilation time tenfold. See VideoToolbox.pch (if you're
  9. using Metrowerks CodeWarrior) or VideoToolbox.c (any other compiler) for 
  10. instructions.
  11.  
  12. My convention is to assign different names to the precompiled header depending
  13. on the compile-time options: use of ppc/68k, 68881, and size of int.
  14.  
  15. The precompilation depends on the sizeof(double) and sizeof(int)
  16. because most functions use or return such values and the external interface must
  17. allow the appropriate amount of space. THINK C supports a 12-byte "universal"
  18. format double that works well both with the 68881 fpu (which uses the top two
  19. bytes and the bottom 8 bytes) and with SANE (which uses the bottom 10 bytes).
  20. Thus in THINK C it is easy to mix modules compiled with (e.g. your code) and
  21. without (e.g. the ANSI library) the 68881 option. Unfortunately that excellent
  22. feature is unique to THINK C. In MPW and CodeWarrior C you must use 10-byte
  23. doubles when you use SANE (i.e. don't use the 68881 fpu), so when you use these
  24. compilers you'll need separate pre-compiled headers, with and without the 68881
  25. option, if you want to compile for each environment: to use the 68881 fpu, or
  26. run on machines that lack it.
  27.  
  28. Metrowerks CodeWarrior project names end in ".µ", and indicate which cpu they
  29. support by "68k" or "ppc". THINK C projects support only the 68k and have names
  30. ending in ".π".
  31.  
  32. My naming convention for pre-compiled headers indicates the size of int, "2i" or
  33. "4i", and, if the 68881 is required, "881". Metrowerks pre-compiled headers
  34. indicate which cpu they support by "68k" or "ppc"; THINK C supports only the
  35. 68k. The THINK C pre-compiled header that I use is "VideoToolbox.pre", which
  36. uses 2-byte ints and "universal" 12-byte doubles that work with or without the
  37. 68881. (The THINK C ANSI library requires 2-byte ints.) The Metrowerks
  38. CodeWarrior C pre-compiled headers that I use are called,
  39. "VideoToolbox.68k.4i.pre", "VideoToolbox.68k.4i.881.pre", and
  40. "VideoToolbox.ppc.pre".
  41.  
  42. As of June 14, 1995, the VideoToolbox #includes <assert.h>, or, if MATLAB
  43. is true, defines a MATLAB-compatible version of assert(). If your source file
  44. #includes <assert.h> then it will be included again, undoing the work
  45. done here, including the MATLAB compatibility. For that reason you should NOT
  46. #include <assert.h> in your source files.
  47.  
  48. MAC_C:
  49.  
  50. Defining the symbol MAC_C as 0 before this file is compiled will leave only the 
  51. stuff that is written in pure Standard C, which will work on any computer.
  52.  
  53. The Apple Macintosh header files use some extensions to C that are not part of
  54. Standard C, e.g. "pascal", "short double", enums larger than ints, and function
  55. prototypes that specify absolute addresses. These keywords and constructions
  56. cannot be compiled in Standard C. The macro MAC_C is defined as true, below,
  57. only on Macintosh C compilers that incorporate these extensions, and is false
  58. otherwise. The MAC_C symbol is used to prevent inclusion of all the
  59. Macintosh-dependent header files and prototypes when the compiler doesn't
  60. support them. However, lacking any general test for these extensions, a test
  61. must be added, below, for each new compiler. At present we test for Symantec C
  62. THINK C, Apple MPW C, and Metrowerks CodeWarrior C.
  63.  
  64. MATLAB:
  65.  
  66. If you want to use the VideoToolbox from within MATLAB then you'll be happy
  67. to know that all the work's been done for you. Get yourself a copy of the 
  68. Psychophysics Toolbox:
  69. <http://www.psych.ucsb.edu/~brainard/software/>
  70.  
  71. The VideoToolbox sources can be linked to create a stand-alone C application, or
  72. a MATLAB external code resource (a "MEX" file), to be invoked by typing the
  73. function name from within MATLAB. In that case we call the THINK C project a
  74. "MATLAB project". A MATLAB project must #define the symbol MATLAB as true for
  75. every C file and must #include the VideoToolbox.h header at the beginning of every
  76. C file. You can simply "#define MATLAB 1"; VideoToolbox.h will redefine the 
  77. "MATLAB" symbol to correspond to the version of MATLAB defined by the MATLAB 
  78. header files, currently version 3, 4, or 5.
  79. Don't #define MATLAB within your C file; use the Edit:Options:THINK C:Prefix
  80. window instead. E.g. you could type
  81.     #define MATLAB 1
  82. into the Prefix window.
  83.  
  84. You must have the file "mex.h" in order to compile this file when "MATLAB" is true.
  85. "mex.h" is distributed by MathWorks as part of MATLAB.
  86.  
  87. If you're using THINK C to create your MEX file, and you use QuickDraw, then
  88. you'll need PsychLibSources.h and CheckConfig.c from the Psychophysics Toolbox.
  89.  
  90. dgp & dhb.
  91. Copyright 1989-1997 © Denis G. Pelli
  92.  
  93. HISTORY: (omitting changes documented in C files)
  94. 2/20/93 dhb    Added various commonly used headers.  
  95.             Restructured so that only VideoToolbox.h has to be included,
  96.             whether one is creating stand-alone THINK C or code resources
  97.             to be called by MATLAB. Everything that cares is properly conditioned
  98.             by the symbol MATLAB.
  99. 7/9/93    dgp    Changed our convention for the MATLAB symbol, defining it as
  100.             1 or 0 instead of defining or leaving undefined. The advantage of
  101.             this approach is that "MATLAB" can now be used as an argument in an
  102.             ordinary if statement, which is much more readable than #if.
  103. 8/21/93    dhb    Added undefs in #if MATLAB so that memory allocation goes through THINK C 
  104.             library, not as callback. Callbacks would be OK except that the Mathworks 
  105.             forgot to give us one for realloc. This leads to mixing memory managers
  106.              on the same pointers -- bad bad bad.
  107. 9/2/93    dhb    commented out #include <TranslateLinefeeds.h> since it's
  108.             not presently compatible with MATLAB.
  109. 9/2/93    dgp    Moved the NL and NEWLINE macros from Assign.c into this file.
  110. 9/8/93    dgp    Mention VideoToolbox.c.
  111. 9/11/93    dhb,dgp    Define STDIO_INT and STDIO_DOUBLE.
  112. 9/12/93    dhb    Change STDIO_... to PRINTF_... and SCANF_...
  113.             Insert conditional for MATLAB 3.5 vs. 4.x
  114. 9/14/93    dhb    Conditional for MATLAB changed to make symbol match major version number.
  115.             Removed traces of old trying to force 4 byte ints for MATLAB.
  116. 9/14/93    dgp    Moved up inclusion of QuickDraw.h before MATLAB stuff, since cmex.h
  117.             requires it. Fixed typo, changing "#elseif" to "#elif".
  118. 9/15/93    dgp    Edited the comments above, referring to VideoToolbox.c and the new 
  119.             VideoToolboxMATLAB.c. (Deleted VideoToolboxMATLAB.c on 9/16/96.)
  120. 9/16/93    dgp    Added contents of former Assign.h.
  121.             Defined MAC_C so that the VideoToolbox.h header may be used with
  122.             Standard C.
  123. 9/16/93    dhb Removed prototype for obsolete GetDateTimeString.
  124. 10/2/93    dgp    Added #include <Errors.h>.
  125. 12/1/93 dgp Now always write "MATLAB" in all caps, since that's the trademarked name.
  126. 12/16/93 dhb Somewhere things got munged.  Conditional for MATLAB version appeared
  127.            before inclusion of cmex, which won't work.  I fixed the order.
  128. 12/16/93 dhb Commented out inclusion of TranslateLineFeeds.h down below.  This
  129.            generates a link error from MATLAB.
  130. 12/29/93 dgp added #include <Packages.h>
  131. 6/12/94  dgp added definition of Apple's new BlockMoveData, for compatibility with
  132.             Apple's old pre-Universal header files.
  133. 6/12/94    dgp #include Strings.h if Universal header files are used.
  134. 7/28/94 dgp Added test for Metrowerks CodeWarrior C.
  135. 9/2/94    dgp #include MacMemory.h
  136. 9/5/94    dgp changed "int" to "short int" in definitions of PRINTF_INT and SCANF_INT for
  137.             MATLAB 4. This is based on common sense, not testing or detailed knowledge.
  138. 3/31/95    dgp    As a gesture of support for Symantec THINK C 8, now define THINK_C.
  139. 5/26/95 dgp Formerly header files whose precompilation depends on the mc68881 or 
  140.         mc68020 THINK C compiler options (i.e. math.h and mc68881.h) were omitted 
  141.         from VideoToolbox.h so that the resulting precompiled header file could be 
  142.         used in projects regardless of those options. However, for Metrowerks CodeWarrior
  143.         there's no advantage to omitting those headers, and a significant increase in
  144.         compile time, as fp.h is recompiled for each file. Since I've switch to
  145.         CodeWarrior, and expect most other users to switch as well, VideoToolbox.h now
  146.         includes math.h or fp.h.
  147. 5/27/95 dgp removed fp.c prototypes because Apple's fp.h now supports both 68k and ppc.
  148. 6/6/95 dgp discarded all references to TranslateLinefeeds.c and TranslateLinefeeds.h, since
  149.         I never got them to work properly, and I don't think they're needed with Metrowerks
  150.         CodeWarrior.
  151. 6/8/95 dgp Made sure that the MATLAB struct "Matrix" is always native aligned.
  152. 6/13/95 dgp define GENERATING68K, GENERATINGPOWERPC, and GENERATING68881 if not already
  153.         defined (as in Apple's latest universal headers). Define GENERATING68020.
  154. 6/14/95    dhb & dgp redefine the assert() macro, redirecting it to PrintfExit, which
  155.         in turn uses mex_error() to report the error. This is needed to get MEX files
  156.         to link properly.
  157. 6/16/95    dhb Fixed MATLAB's SCANF_INT etc. for __MWERKS__.
  158. 6/16/95 dgp moved the definitions of GENERATING68K to the top of this file, so that
  159.         the MATLAB conditionals can use them.
  160. 6/16/95    dhb    & dgp now #include <assert.h>, unless MATLAB is defined, in which case
  161.         we define a MATLAB-compatible version of the assert macro. Just in case,
  162.         leave NDEBUG defined to disable the standard assert macro which may be
  163.         brought in if the user's source files #include <assert.h>.
  164. 6/16/95    dhb    Fixed longstanding bug (in SCANF_INT??).
  165. 6/23/95    dhb    Include prototypes for AfterDark.c and IsFileSharingOn.c.
  166. 7/19/95 dgp Added changes suggested by Stefan Treue, streue@bcm.tmc.edu, for compatibility
  167.         with Symantec C. Eliminated use of //-style comments. Now include math.h
  168.         when compiling for Standard C, i.e. MAC_C is false.
  169. 8/10/95 dgp Include MacMemory.h ONLY for THINK C, not for Symantec C, since I don't
  170.         have any reason to think that Symantec C memory management is bad.
  171. 8/13/95 dgp Removed definition of THINK_C for SYMANTEC_C. It seems better to leave
  172.         the compiler's macros alone. Changed conditionals throughout the VideoToolbox
  173.         to deal with all the special cases: THINK_C, THINK_CPLUS, and SYMANTEC_C.
  174. 3/5/96    dhb Add conditional to prevent inclusion of <fp.h> and instead include <math.h>
  175.         when THINK_C is true.  This is needed to compile under THINK_C 8.  I suspect
  176.         that this used to work because the universal headers variable was < 2.
  177. 4/1/96    dgp removed "MAC_C" requirement for inclusion of fp.h. Tried to make VideoToolbox.h
  178.         more consistent with q_include.h, so both will work separately or together, in
  179.         either order, but I haven't checked whether I succeeded.
  180. 8/29/96    dhb & dgp updated for compatibility with MATLAB 5.
  181. 8/31/96 dhb  At dgp's suggestion, added macro mexFunctionEntry, which properly declares the
  182.         routine mexFunction according to which MATLAB version is being compiled.  Note that
  183.         prhs is declared as inprhs so that you can set prhs = inprhs and then modify it 
  184.         when compiling under version 5.  This assignment needs to be done in all source files.
  185. 9/5/95    dgp if !UNIVERSAL_HEADERS, typedef UInt32 and UnsignedWide, and prototype Microseconds.
  186. 11/96 dgp changed argument name from "explicit" to "isExplicit" since "explicit" is keyword in C++.
  187. 12/23/96 dgp now set MATLAB to MATLAB_VERSION, if defined (i.e. version 5 on).
  188. 1/22/97 dhb  Added prototype for IsAfterDarkEnabled.
  189. 1/25/97 dgp if MATLAB==4 #define mexWarnMsgTxt printf
  190. 2/17/97    dgp    if MATLAB==4 #define mexWarnMsgTxt printf("%s",s)
  191. 3/4/97    dhb    mexWarnMsgTxt conditionally uses TranslateEOL.
  192.         dhb Conditional macro for mexErrMsgTxt.
  193.         dhb    Prototype for TranslateEOL.
  194. 3/5/97    dgp    added Printf prototype. Polished the conditionals for THINK C MATLAB.
  195. 3/5/97    dgp    as suggested by david brainard, removed the obsolete NL and NEWLINE stuff.
  196. 3/13/97    dgp I upgraded to the latest THINK C, from the Symantec C++ 8 release 5  CD-ROM.
  197.             (THINK Project Manager 7.05; "translator" THINK C 8.0 or 8.1d1.)
  198.             Symantec has announced that they will no longer develop C or C++, so this is
  199.             probably the LAST version of THINK C. In this release, Symantec changed math.h:
  200.             removing "pi", and screwing up the definition of "long double" so that <math.h>
  201.             generates a compiler error when you use the "native floating point" and "8 byte double"
  202.             settings that are required to generate a MEX resource file for MATLAB.
  203.             With David Brainard's help, I've added conditionals to VideoToolbox.h to
  204.             work around both limitations. Unfortunately this new version of VideoToolbox.h
  205.             may not be compatible with the <math.h> included by Symantec with earlier versions
  206.             of THINK C. Sorry, please blame Symantec, not me. Over the past year,
  207.             David and I have worked with three different versions of THINK_C, all with
  208.             different versions of <math.h>, that nevertheless all identify themselves by
  209.             setting the preprocessor symbol THINK_C to 7. That makes it really hard for a
  210.             simple header file to provide version-specific fixs. (The conditionals are
  211.             specific to THINK_C so other compilers won't be affected.)
  212. 3/19/97    dgp    enhanced the VBLTaskAndA5 struct, removing the obsolete timer field, and adding
  213.             a new "seconds" field, as documented in VBLInstall.c
  214. 3/22/97    dgp    the definition of mex_qd, used solely by THINK C MEX projects, has been moved from
  215.             here to CheckConfig.c in the Psychophysics Toolbox, which may be obtained from:
  216.             <http://www.psych.ucsb.edu/~brainard/software/>
  217. 3/27/97    dgp    Updated the code defining GENERATING68881 to work with Apple's latest Universal Headers,
  218.             which now define that symbol, though they don't support THINK C. It now seems pointless
  219.             to retain support for Apple's pre-universal headers, so I've started stripping out
  220.             such code.
  221. */
  222. #pragma once            /*  suppress multiple inclusions of this file */
  223. #ifndef _VIDEOTOOLBOX_    /*  suppress multiple inclusions of this file */
  224. #define _VIDEOTOOLBOX_
  225. /*
  226. Header files that are required for successful compilation of the rest of this
  227. file are marked "required".
  228. */
  229. #if !defined(MAC_C)
  230.     #if THINK_C    || THINK_CPLUS || SYMANTEC_C || defined(__SC__)            \
  231.         || applec            /* MPW C, presumably with Mac extensions */    \
  232.         || __MWERKS__        /* Metrowerks CodeWarrior C, " */
  233.         /* Set MAC_C to true only if the "pascal" keyword is allowed. */
  234.         #if THINK_C && !SYMANTEC_C
  235.             #if !__option(thinkc)
  236.                 #define MAC_C 0    /* Standard C */
  237.             #endif
  238.         #endif
  239.         #if SYMANTEC_C
  240.             #if __option(ansi_strict)
  241.                 #define MAC_C 0    /* Standard C */
  242.             #endif
  243.         #endif
  244.         #if __MWERKS__
  245.             #if __option(ANSI_strict) || __option(only_std_keywords)
  246.                 #define MAC_C 0    /* Standard C */
  247.             #endif
  248.         #endif
  249.         #if !defined(MAC_C)
  250.             #define MAC_C 1    /* allow Mac C extensions: "pascal", etc. */
  251.         #endif
  252.     #else
  253.         #define MAC_C 0        /* Standard C */
  254.     #endif
  255. #endif
  256. #ifndef SHORT_DOUBLE_OK
  257.     #if SYMANTEC_C
  258.         #define SHORT_DOUBLE_OK 0        /* "short double" not supported by Symantec C */
  259.     #else
  260.         #define SHORT_DOUBLE_OK MAC_C    /* "short double" not allowed by Standard C */
  261.     #endif
  262. #endif
  263. #include <stdio.h>            /*  required */
  264. #include <stdlib.h>
  265. #if MAC_C
  266.     #include <Quickdraw.h>    /*  required */
  267. #endif
  268. /*
  269. The inclusion, above, of Quickdraw.h will result in the inclusion of MixedMode.h
  270. only if the Universal Headers are used, since the Universal Headers and the Mixed
  271. Mode Manager are both new, providing universal support for 68k and ppc Macs.
  272. */
  273. #if defined(__MIXEDMODE__)
  274.     #if defined(GENERATINGPOWERPC) || defined(GENERATING68K)
  275.         #define UNIVERSAL_HEADERS 2    /* version 2 */
  276.     #else
  277.         #define UNIVERSAL_HEADERS 1    /* version 1 */
  278.     #endif
  279. #else
  280.     #define UNIVERSAL_HEADERS 0
  281.     #error "Need Apple's Universal Headers"
  282. #endif
  283.  
  284. /* Apple's ConditionalMacros.h header defines GENERATING68881, but doesn't support THINK C,
  285. so we handle that case here. */
  286. #if THINK_C || THINK_CPLUS
  287.     #undef GENERATING68881
  288.     #if THINK_C && THINK_C==1        /* THINK C 4 */
  289.         #define GENERATING68881 _MC68881_
  290.     #endif
  291.     #if THINK_CPLUS || (THINK_C && THINK_C>1)    /* THINK C 5,6,7,8, C++, SYMANTEC C,C++ */
  292.         #if __option(mc68881)
  293.             #define GENERATING68881 1
  294.         #endif
  295.     #endif
  296. #endif
  297. #ifndef GENERATING68881
  298.     #define GENERATING68881 0
  299. #endif
  300.  
  301. /* Apple's headers don't define GENERATING68020, but Identify.c and Require.c need it. */
  302. #if GENERATING68K && !defined(GENERATING68020)
  303.     #if defined(applec) || defined(__SC__)
  304.         #ifdef mc68020
  305.             #define GENERATING68020 1
  306.         #endif
  307.     #else
  308.         #if THINK_C && THINK_C==1            /* THINK C 4 */
  309.             #define GENERATING68020 _MC68020_
  310.         #endif
  311.         #if SYMANTEC_C || THINK_CPLUS || (THINK_C && THINK_C>1)    /* Symantec C, THINK C 5,6,7,8 */
  312.             #if __option(mc68020)
  313.                 #define GENERATING68020 1
  314.             #endif
  315.         #endif
  316.         #if __MWERKS__
  317.             #if __MC68020__
  318.                 #define GENERATING68020 1
  319.             #endif
  320.         #endif
  321.     #endif
  322. #endif
  323. #if !defined(GENERATING68020)
  324.     #define GENERATING68020 0
  325. #endif
  326.  
  327. #if !defined(MATLAB)
  328.     #define MATLAB 0
  329. #endif
  330. #if MATLAB
  331.     /*
  332.     This must come after stdlib.h, stdio.h, and QuickDraw.h, and before everything
  333.     else. If MATLAB is true then we include the header file cmex.h.  Otherwise we
  334.     define the data types that are normally provided by that header, so that code
  335.     that uses these types may be compiled for use in applications.  It must come
  336.     before we test for version.  The version 3 cmex.h does not define the
  337.     symbol mex_h; subsequent versions do.  This is what we use to figure out which
  338.     version we are compiling for.  Sound complicated?  Sigh! dhb
  339.     */
  340.     
  341.     #include "mex.h"
  342.     /* Test for MATLAB version 5,4, or 3, and set symbol appropriately. */
  343.     #undef MATLAB
  344.     #ifdef mex_h
  345.         #ifdef MATLAB_VERSION
  346.             #define MATLAB MATLAB_VERSION    /* for version 5 and higher */
  347.         #else
  348.             #define MATLAB 4
  349.         #endif
  350.     #else
  351.         #define MATLAB 3
  352.     #endif
  353.     #if !MAC_C
  354.         #error "MATLAB requires the Macintosh extensions to C."
  355.     #endif
  356.  
  357.     /*
  358.     Undefine the macros that override memory allocation.  MATLAB's implementation
  359.     doesn't work if you use realloc.
  360.     */
  361.     #undef malloc
  362.     #undef calloc
  363.     #undef free
  364.     
  365.     /* Define data types for printf, scanf. */
  366.     #if (MATLAB == 4 || MATLAB == 5)
  367.     /* Version 4 or 5 */
  368.         #if GENERATING68K
  369.             typedef short int PRINTF_INT;        /* type of arguments to printf et al. */
  370.             typedef long double PRINTF_DOUBLE;
  371.             typedef    int SCANF_INT;                /* type of arguments to scanf et al. */
  372.             typedef double SCANF_DOUBLE;
  373.         #endif
  374.         #if GENERATINGPOWERPC
  375.             typedef int PRINTF_INT;                /* type of arguments to printf et al. */
  376.             typedef double PRINTF_DOUBLE;
  377.             typedef int SCANF_INT;                /* type of arguments to scanf et al. */
  378.             typedef double SCANF_DOUBLE;
  379.         #endif
  380.         #if THINK_C || THINK_CPLUS
  381.             // redirect all printing to go through TranslateEOL() in PrintfExit.c
  382.             #undef printf
  383.             #undef mexPrintf
  384.             #undef mexErrorMsgTxt
  385.             #define printf Printf
  386.             #define mexPrintf Printf
  387.             #define mexErrMsgTxt(s) mexErrMsgTxt(TranslateEOL(s))
  388.         #endif
  389.         #if MATLAB == 4
  390.             #define mxArray Matrix
  391.             #define mxREAL REAL
  392.             #define mxIsChar mxIsString
  393.             #define mxDestroyArray mxFreeMatrix
  394.             #define mxCreateDoubleMatrix mxCreateFull
  395.             typedef mxArray CONSTmxArray;
  396.             #undef mexWarnMsgTxt
  397.             #if THINK_C || THINK_CPLUS
  398.                 #define mexWarnMsgTxt(s) Printf("%s",s)
  399.             #else
  400.                 #define mexWarnMsgTxt(s) printf("%s",s)
  401.             #endif
  402.         #else
  403.             typedef const mxArray CONSTmxArray;
  404.             #if THINK_C || THINK_CPLUS
  405.                 #undef mexWarnMsgTxt
  406.                 #define mexWarnMsgTxt(s) mexWarnMsgTxt(TranslateEOL(s))
  407.             #endif
  408.         #endif
  409.     #endif
  410. #else
  411.     typedef long int INT;
  412.     #if SHORT_DOUBLE_OK
  413.         typedef short double DOUBLE;/* not allowed by Standard C */
  414.     #else
  415.         typedef double DOUBLE;
  416.     #endif
  417.     typedef int PRINTF_INT;            /* type of arguments to printf et al. */
  418.     typedef double PRINTF_DOUBLE;
  419.     typedef int SCANF_INT;            /* type of arguments to scanf et al. */
  420.     typedef double SCANF_DOUBLE;
  421.     #if SHORT_DOUBLE_OK
  422.         #if PRAGMA_ALIGN_SUPPORTED || __MWERKS__
  423.             #pragma options align=native
  424.         #endif
  425.         typedef struct {
  426.             char *name;
  427.             INT type;
  428.             INT m;
  429.             INT n;
  430.             DOUBLE *pr;
  431.             DOUBLE *pi;
  432.         } Matrix;
  433.         #if PRAGMA_ALIGN_SUPPORTED || __MWERKS__
  434.             #pragma options align=reset
  435.         #endif
  436.     #endif
  437. #endif
  438.  
  439. /*  Standard C headers */
  440. #if MATLAB
  441.     /* The <assert.h> macro requires modification to work in a MATLAB shared library. */
  442.     #define NDEBUG        /* disable the standard assert.h macro */
  443.     #undef assert
  444.     #define assert(x)    if(!(x)){\
  445.         PrintfExit("Assertion (" #x ") failed at %s:%d",__FILE__,__LINE__);\
  446.     }
  447. #else
  448.     #include <assert.h>
  449. #endif
  450. #include <ctype.h>
  451. #include <float.h>
  452. #include <limits.h>
  453. #include <stdlib.h>
  454. #include <string.h>
  455. #include <time.h>
  456. #if !defined(__MATH__) && (UNIVERSAL_HEADERS>=2) && !(THINK_C || THINK_CPLUS)
  457.     #include <fp.h>
  458. #else
  459.     #if GENERATINGPOWERPC || GENERATING68881
  460.         /* as advised by math.h, we don't enable these if using 8-byte doubles on 68k */
  461.         #undef _NOERRORCHECK_
  462.         #undef _INLINE_FPU_CALLS_
  463.         #define _NOERRORCHECK_ 1        /* encourage use of 8881 intrinsic functions */
  464.         #define _INLINE_FPU_CALLS_ 1    /* encourage use of 8881 intrinsic functions */
  465.     #endif
  466.     #if THINK_C==7                        // Fix THINK C <math.h> in Symantec's C++ 8 release 5.
  467.         #define SAVE_THINK_C 7
  468.         #undef THINK_C
  469.         #define THINK_C 0
  470.     #endif
  471.     #include <math.h>
  472.     #if SAVE_THINK_C==7                    // Restore "THINK_C".
  473.         #undef THINK_C
  474.         #define THINK_C 7
  475.         #undef SAVE_THINK_C
  476.     #endif
  477.     #if !defined(__FP__)    /* make sure that math.h hasn't included fp.h */
  478.         #undef round
  479.         #define round(x) floor(0.5+(x))    /* used by many VideoToolbox routines */
  480.     #endif
  481. #endif
  482.  
  483. /*  Macintosh headers */
  484. #if MAC_C
  485.     #if THINK_C || THINK_CPLUS || SYMANTEC_C
  486.         #include <console.h>
  487.     #endif
  488.     #include <Devices.h>
  489.     #include <Errors.h>
  490.     #include <Events.h>
  491.     #include <FixMath.h>
  492.     #include <Fonts.h>
  493.     #if UNIVERSAL_HEADERS>2
  494.         #include <Gestalt.h>    /* Apple abbreviated the filename */
  495.     #else
  496.         #include <GestaltEqu.h>
  497.     #endif
  498.     #include <Memory.h>
  499.     #include <Menus.h>
  500.     #include <OSEvents.h>
  501.     #include <OSUtils.h>    /*  required */
  502.     #include <Packages.h>
  503.     #include <Palettes.h>
  504.     #if (THINK_C || THINK_CPLUS || SYMANTEC_C)
  505.         #include <profile.h>/* only needed if you want timing info */
  506.     #endif
  507.     #include <QDOffscreen.h>
  508.     #include <Resources.h>
  509.     #include <Retrace.h>    /*  required */
  510.     #if __MWERKS__
  511.         #include <SIOUX.h>
  512.     #endif
  513.     #include <Slots.h>
  514.     #include <Sound.h>
  515.     #if THINK_C && !UNIVERSAL_HEADERS
  516.         #include <pascal.h>    /* CtoPStr() and PtoCStr() */
  517.         #ifndef c2pstr
  518.             #define c2pstr(s) CtoPstr(s)
  519.             #define p2cstr(s) PtoCstr(s)
  520.         #endif
  521.     #else
  522.         #include <Strings.h>/* c2pstr() and p2cstr() */
  523.         #define CtoPstr c2pstr
  524.         #define PtoCstr p2cstr
  525.     #endif
  526.     #include <Timer.h>        /*  required */
  527.     #include <ToolUtils.h>
  528.     #include <Traps.h>
  529.     #include <Video.h>
  530.     #include <Windows.h>    /*  required */
  531.     /*
  532.     Old Memory.h header files, before Apple's Universal Headers, don't define the new
  533.     BlockMoveData(), so we do it here, to retain compability with the old header files.
  534.     */
  535.     #if !UNIVERSAL_HEADERS
  536.         #pragma parameter BlockMoveData(__A0,__A1,__D0)
  537.         extern pascal void BlockMoveData(const void *srcPtr,void *destPtr,Size byteCount)=0xA22E;
  538.     #endif
  539. #endif
  540.  
  541. /*
  542. This redefines the standard C functions, malloc, etc. to instead call Apple's
  543. corresponding routines, e.g. NewPtr. The THINK C memory management routines are 
  544. poor because they are bad about freeing space, tending to fragment the free space. 
  545. */
  546. #if THINK_C && !defined(SYMANTEC_C)
  547.     #include "MacMemory.h"
  548. #endif
  549.  
  550. /*
  551. TRUE and FALSE
  552. */
  553. #ifndef TRUE
  554.     #define FALSE    0
  555.     #define TRUE    1
  556. #endif
  557.  
  558. /*
  559. NAN & INF
  560. If you're using NAN and INF you'll be interested in the IsNan(), IsInf(), and
  561. IsFinite() definitions & prototypes below. 
  562. Apple's fp.h header defines isnan() and isfinite().
  563. Apple's header files math.h and fp.h both define HUGE_VAL and pi.
  564. fp.h also defines INFINITY, NAN, isfinite(), and isnan().
  565. */
  566. #if !defined(INF)
  567.     #define INF HUGE_VAL    /* HUGE_VAL is defined in math.h and fp.h */
  568. #endif
  569. #if !defined(NAN)
  570. /*    #define NAN    (0.0/0.0)    */    /* evaluated at runtime */
  571.     #define NAN    Nan            /* global defined in Nan.c */
  572. #endif
  573.  
  574. /*
  575. NUMERICAL CONSTANTS
  576. It's sad to say, but THINK C 5.02 loses two bits of precision converting between
  577. doubles and ascii text, in either direction. Thus you will obtain more accurate
  578. results by computing the numerical constants below at runtime rather than using
  579. these predefined constants. The ANSI Numerical C Extensions group is moving to
  580. require C compilers to preserve precision, so there is hope for the future. Of
  581. course most applications would never notice a loss of two bits precision out of
  582. the total double precision given by the 64 bits in the mantissa.
  583. */
  584. #if !defined(PI)
  585.     #if UNIVERSAL_HEADERS>=2 && !(THINK_C || THINK_CPLUS)
  586.         #define PI        pi                        /* pi is defined in math.h and fp.h */
  587.     #else
  588.         #define PI        3.1415926535897932385    /* computed in Mathematica */
  589.     #endif
  590. #endif
  591. #if !defined(LOGPI)
  592.     #define LOGPI    1.14472988584940017414    /* computed in Mathematica */
  593. #endif
  594. #if !defined(LOG2)
  595.     #define LOG2    0.69314718055994530942    /* computed in Mathematica */
  596. #endif
  597. #if !defined(LOG10)
  598.     #define LOG10    2.30258509299404568402    /* computed in Mathematica */
  599. #endif
  600.  
  601. #if MAC_C
  602.     /*
  603.     CLUTSIZE
  604.     Inline code that returns the same answer as GDClutSize(device).
  605.     */
  606.     #define GDCLUTSIZE(device) (gdClutSizeTable[(**(**(device)).gdPMap).pixelSize])
  607.     
  608.     /*  Commented out, because its answer is misleading when in 16-bit or 32-bit mode. */
  609.     /* #define GDCOLORS(device) ((**(**(**device).gdPMap).pmTable).ctSize+1) */
  610. #endif
  611.  
  612. /*
  613. FIXED POINT ARITHMETIC
  614. Apple defines a handy data type called Fixed that is stored in a long, but is
  615. assumed to have a decimal point in the middle. Many operations, e.g. adding two
  616. Fixed numbers or multiplying or dividing a Fixed by an integer, can be performed
  617. directly. To multiply or divide two Fixed numbers use Apple's FixMul() and
  618. FixDiv(). FixRatio(n,m) returns the Fixed ratio of two integers. Macintosh C
  619. compilers define double in various ways, depending on whether a floating point
  620. unit is to be used. The Apple-provided routines for doing type conversion to and
  621. from Fixed are only appropriate if you are NOT using the floating point unit.
  622. The ones defined below are faster and work with or without the FPU.
  623. */
  624. #define LongToFix(x) ((long)(x)<<16)
  625. #define FixToLong(x) ((x)>>16)
  626. #define DoubleToFix(x) ((long)((x)*65536.+0.5))
  627. #define FixToDouble(x) ((double)(x)*(1./65536.))
  628.  
  629. #if MAC_C
  630.     /*
  631.     StackGrow(n) increases the stack allocation by n bytes. You'll also want to use
  632.     Apple's StackSpace(), declared in Memory.h, that returns the number of bytes 
  633.     allocated for the stack.
  634.     */
  635.     #define StackGrow(extraBytes) SetApplLimit(GetApplLimit()-(extraBytes))
  636. #endif
  637.  
  638. #if MAC_C
  639.     /* AfterDark.c */
  640.  
  641.     OSErr AfterDarkEnable(void);
  642.     OSErr AfterDarkDisable(void);
  643.     Boolean IsAfterDarkEnabled(void);
  644.  
  645. #endif
  646.  
  647. /* Assign.c */
  648.  
  649. #define ASSIGN_DIMS 3        /* Feel free to increase or decrease ASSIGN_DIMS. */
  650. typedef struct {
  651.     short type;
  652.     unsigned sizedOnce:1;    /* dim[] is meaningful */
  653.     unsigned sized:1;        /* dim[] is final */
  654.     unsigned malloced:1;    /* allocated by malloc */
  655.     char *name;
  656.     void *ptr;                /* for array, address of element zero */
  657.     long dim[ASSIGN_DIMS];    /* zero indicates a scalar */
  658.     long firstElement;        /* for 1-d array, index of first array element. Usually 0 */
  659.     const char *comment;    /* text string, or NULL */
  660. } Description;
  661. enum{assignReportUnknown=1,assignNoHexInts=2,assignHexFloats=4
  662.     ,assignNoComment=8,assignNoPrintfExit=0x10
  663.     ,assignEchoAssignments=0x20,assignEchoComments=0x40,assignEchoFile=0x80
  664. };
  665. enum {assignMemoryError=-1,assignTypeError=-2
  666.     ,assignVariableError=-3,assignUnknownVariableError=-4
  667.     ,assignSubscriptError=-5,assignSubscriptBoundsError=-6
  668.     ,assignEqualsError=-7,assignConstantError=-8,assignHexError=-9
  669.     ,assignSemicolonError=-10,assignFileError=-11
  670.     ,assignInconsistentDescriptionsError=-12,assignUnequalDataError=-13
  671.     ,assignInconsistentDimensionsError=-14
  672.     ,assignCouldntFindDescription=-15
  673. };
  674. enum{charType=1,unsignedCharType,shortType,unsignedShortType
  675.     ,longType,unsignedLongType
  676.     ,floatType
  677.     #if SHORT_DOUBLE_OK
  678.         ,shortDoubleType
  679.     #endif
  680.     ,doubleType
  681.     ,charPtrType,unsignedCharPtrType,shortPtrType,unsignedShortPtrType
  682.     ,longPtrType,unsignedLongPtrType
  683.     ,floatPtrType
  684.     #if SHORT_DOUBLE_OK
  685.         ,shortDoublePtrType
  686.     #endif
  687.     ,doublePtrType
  688.     ,stringType,unknownType
  689. };
  690. FILE *OpenCalFileRead(char *filename);
  691. FILE *OpenCalFileReadAndCheck(char *filename);
  692. FILE *OpenCalFileWrite(char *filename);
  693. void AppendDescriptions(Description **d,Description *s);
  694. void CopyDescriptions(Description *d,Description *s);
  695. Description *AllocateDescriptions(long n);
  696. void FreeDescriptions(Description *d);
  697. long NumberOfDescriptions(Description *d);
  698. Description NullDescription(void);
  699. int IsNullDescription(Description d);
  700. #define IsNullDescription(d) ((d).type==0)
  701. int AssignmentLineWasBlank(void);
  702. int UnequalDescribedVars(Description d1[],Description d2[],short flags);
  703. int UnequalDescribedVarPair(Description *d1,Description *d2,short flags);
  704. int CopyDescribedVars(Description d1[],Description d2[],short flags);
  705. int CopyDescribedVarPair(Description *d1,Description *d2,short flags);
  706. long InitializeADescribedVar(Description *d,short flags);
  707. long InitializeDescribedVars(Description d[],short flags);
  708. long FindDescribedDim(Description d[],void *ptr,int i,short flags);
  709. long FindDescription(Description d[],void *ptr,short flags);
  710. void FreeADescribedVar(Description *d,short flags);
  711. void FreeDescribedPtrVars(Description d[],short flags);
  712. void FreeDescribedVars(Description d[],short flags);
  713. void KeepDescribedVars(Description d[],short flags);
  714. void KeepADescribedVar(Description *d,short flags);
  715. long PrintAnAssignment(FILE *stream,Description *d,short flags);
  716. long PrintAssignments(FILE *stream,Description d[],short flags);
  717. long PrintAssignmentsToFile(const char *filename,Description d[],short flags);
  718. long ReadAssignmentLine(FILE *stream,Description d[],short flags);
  719. long ReadAssignmentBlock(FILE *stream,Description d[],short flags);
  720. long ReadAssignmentStream(FILE *stream,Description d[],short flags);
  721. long ReadAssignmentFile(const char *filename,Description d[],short flags);
  722. Description Describe(short type,void *ptr,char *name,const char *comment);
  723. Description DescribeArray(short type,void *ptr,char *name,const char *comment,...);
  724. Description DescribeFirstLast(short type,void *ptr,char *name
  725.     ,const char *comment,long firstElement,long lastElement);
  726.  
  727. #if MAC_C
  728.     /* AtExitToShell.c */
  729.     
  730.     int AtExitToShell(void(*userFunctionPtr)(void));
  731. #endif
  732.  
  733. /* Binomial.c */
  734.  
  735. long    BinomialSample(double p,long n);
  736. int        BinomialSampleQuickly(int n);
  737. double    BinomialLowerBound(double P,long k,long n);
  738. double    BinomialUpperBound(double P,long k,long n);
  739. double    BinomialPdf(double p,long k,long n);
  740. double    Binomial(double p,long k,long n);
  741. double    IncompleteBeta(double x,double a,double b);
  742. double    InverseBinomial(double P,long k,long n);
  743. double    InverseIncompleteBeta(double p,double a,double b);
  744.  
  745. /* BreakLines.c */
  746.  
  747. char *BreakLines(char *string,long lineLength);
  748. void PrintWrappedText(FILE *stream,const char *s);
  749. void PrintWrappedTextToFile(const char *filename,const char *s);
  750. void PrintWrappedComment(FILE *stream,const char *s);
  751. void PrintWrappedCommentToFile(const char *filename,const char *s);
  752.  
  753. #if MAC_C
  754.     /* CardSlot.c */
  755.     
  756.     OSErr    CardSlot(char *cardName);
  757.     
  758.     /* CenterRectInRect.c */
  759.     
  760.     void CenterRectInRect(Rect *moveableRectPtr,Rect *fixedRectPtr);
  761.     void PinRectInRect(Rect *a,Rect *b);
  762.     void OffsetRectTile(Rect *r,int nx,int ny);
  763.     Boolean IsRectInRect(Rect *r,Rect *R);
  764.     void ShrinkRect(Rect *r,int hDivisor,int vDivisor);
  765.     void ExpandRect(Rect *r,double hMag,double vMag);
  766.     void ExpandAndOffsetRect(Rect *r,double hMag,double vMag,double hOffset,double vOffset);
  767.     void LocalToGlobalRect(Rect *r);
  768.     void GlobalToLocalRect(Rect *r);
  769.  
  770. #endif
  771.  
  772. /* ChiSquare.c */
  773.  
  774. double    PChiSquare (double chiSquare,int n);
  775.  
  776. /* Choose.c */
  777.  
  778. #if !MAC_C
  779.     #define Boolean unsigned char
  780. #endif
  781. int Choose(int defaultChoice,const char *query,char *choices[],int n);
  782. char *ChoiceStr(char *choices[],int n);
  783. int MultipleChoice(short defaultChoice,short n,char *choices[]);
  784. Boolean YesOrNo(Boolean defaultAnswer);
  785. extern char *noYes[];
  786. #if !MAC_C
  787.     #undef Boolean
  788. #endif
  789.  
  790. #if MAC_C
  791.     /* ChooseScreen.c */
  792.     
  793.     int ChooseScreen(int screen,const char *question);
  794.  
  795.     /* CommandPeriod.c */
  796.  
  797.     Boolean CommandPeriod(void);
  798.     short    GetNextEventOrQuit(int mask,EventRecord *eventPtr);
  799.     Boolean WaitNextEventOrQuit(int mask,EventRecord *eventPtr,unsigned long sleep,RgnHandle mouseRgn);
  800.  
  801.     /* ConvolveX.c */
  802.     
  803.     void ConvolveX(double f[],int dim,BitMap *srcBits,BitMap *dstBits,
  804.                 Rect *srcRectPtr,Rect *dstRectPtr);
  805.  
  806.     /* ConvolveY.c */
  807.     
  808.     void ConvolveY(double f[],int dim,BitMap *srcBits,BitMap *dstBits,
  809.                 Rect *srcRectPtr,Rect *dstRectPtr);
  810.     
  811.     /* CopyBitsQuickly.c */
  812.     
  813.     enum{addOverQuickly=40,addOverParallel=40,mulOver};
  814.     int    CopyBitsQuickly(BitMap *srcBits,BitMap *dstBits
  815.         ,Rect *srcRectPtr,Rect *dstRectPtr,long srcMode,RgnHandle maskRgn);
  816.     
  817.     /* CopyQuickDrawGlobals.c */
  818.     
  819.     void CopyQuickDrawGlobals(void);
  820.     #define CopyQuickdrawGlobals CopyQuickDrawGlobals    /*  old spelling */
  821.     
  822.     /* CopyWindows.c */
  823.     
  824.     enum{copyLiterally=0x10000,copyColorize=0x20000};
  825.     enum{srcCopyLiterally=srcCopy+copyLiterally,addOverLiterally=addOver+copyLiterally
  826.         ,addOverParallelLiterally=addOverParallel+copyLiterally
  827.         ,mulOverLiterally=mulOver+copyLiterally};
  828.     int CopyWindows(CWindowPtr srcWindow,CWindowPtr dstWindow
  829.         ,Rect *srcRectPtr,Rect *dstRectPtr,long srcMode,RgnHandle maskRgn);
  830.  
  831.     /* CreateTrialSnds.c */
  832.     
  833.     void CreateTrialSnds(void);
  834. #endif
  835.  
  836. /* DatedString.c */
  837.  
  838. char    *DatedString(unsigned long seconds);
  839.  
  840. #if MAC_C
  841.     /* DrawPrintf.c */
  842.     
  843.     void DrawPrintf(char *s, ...);
  844. #endif
  845.  
  846. /* Exponential.c */
  847.  
  848. double ExponentialPdf(double x);
  849.  
  850. /* ffprintf.c */
  851.  
  852. int ffprintf(FILE *stream[2],char *format,...);
  853.  
  854. #if MAC_C
  855.     /* FlushCacheRange.c */
  856.     
  857.     void FlushCacheRange (void *address, unsigned long count);
  858.     
  859.     /* GDOpenWindow.c */
  860.     
  861.     void AddExplicitPalette(WindowPtr window);
  862.     void RemovePalette(WindowPtr window);
  863.     WindowPtr GDOpenWindow1(GDHandle device);
  864.     void GDDisposeWindow1(WindowPtr window);
  865.     CWindowPtr GDOpenWindow(GDHandle device);
  866.     void GDDisposeWindow(CWindowPtr myWindow);
  867.     void GDGrayColorTable(GDHandle device);
  868.     void GDStandardColorTable(GDHandle device,Boolean isColor);
  869.     void SwapWindowExplicitMode(CWindowPtr window,Boolean *isExplicit);
  870.     BitMap *GetBitMapPtr(CWindowPtr window);
  871.     Boolean IsGWorldPtr(CWindowPtr window);
  872.     Boolean IsGrafPtr(CWindowPtr window);
  873.     
  874.     /* GDPrintf.c */
  875.     
  876.     void GDPrintf(char *s, ...);
  877.     
  878.     /* GDTime.c */
  879.     
  880.     double GDFrameRate(GDHandle device);
  881.     double GDMovieRate(GDHandle device,int quickly);
  882.     double GDMovieSize(GDHandle device,int quickly);
  883.     double GDVBLRate(GDHandle device);
  884.     double TickRate(void);
  885.     typedef OSErr (*SetEntriesFunction)(GDHandle device,short start,short count
  886.         ,ColorSpec *aTable);
  887.     OSErr GDTimeClut(GDHandle device,SetEntriesFunction function,short clutEntries
  888.         ,double *sPtr,double *framesPtr,double *missingFramesPtr,double *frameRatePtr);
  889.     
  890.     /* GDVideo.c */
  891.     
  892.     #define MAX_SCREENS 8
  893.     OSErr DriverGestalt(int refNum,OSType driverGestaltSelector,unsigned long *driverGestaltResponsePtr);
  894.     OSErr GDGestalt(GDHandle device,OSType driverGestaltSelector,unsigned long *driverGestaltResponsePtr);
  895.     Boolean GDGestaltIsOn(GDHandle device);
  896.     char  *GDCardName(GDHandle device);
  897.     extern short gdClutSizeTable[33];
  898.     short GDClutSize(GDHandle device);
  899.     long GDColors(GDHandle device);
  900.     OSErr GDControl(int refNum,int csCode,Ptr csParamPtr);
  901.     short GDDacSize(GDHandle device);
  902.     OSErr GDDirectSetEntries(GDHandle device,short start,short count,ColorSpec *aTable);
  903.     OSErr GDDisposeGamma(GDHandle device);
  904.     OSErr GDGetDisplayMode(GDHandle device,unsigned long *displayModeIDPtr
  905.         ,unsigned short *modePtr,unsigned short *pagePtr,Ptr *baseAddrPtr);
  906.     OSErr GDGetNextResolution(GDHandle device,unsigned long previousDisplayModeID
  907.         ,unsigned long *displayModeIDPtr,unsigned long *horizontalPixelsPtr
  908.         ,unsigned long *verticalLinesPtr,Fixed *refreshRatePtr
  909.         ,unsigned short *maxDepthModePtr);
  910.     OSErr GDGetDefaultGamma(GDHandle device,GammaTbl **gammaTbl);
  911.     OSErr GDGetDefaultMode(GDHandle device,short *modePtr);
  912.     OSErr GDGetDelay(GDHandle device,Boolean *dontWaitForVBLPtr,double *nanosecondsPtr);
  913.     OSErr GDGetEntries(GDHandle device,short start,short count,ColorSpec *aTable);
  914.     OSErr GDGetGamma(GDHandle device,GammaTbl **myGammaTblHandle);
  915.     OSErr GDGetGray(GDHandle device,Boolean *flagPtr);
  916.     OSErr GDGetInterrupt(GDHandle device,Boolean *flagPtr);
  917.     OSErr GDGetMode(GDHandle device,short *modePtr,short *pagePtr,Ptr *baseAddrPtr);
  918.     OSErr GDGetPageBase(GDHandle device,short page,Ptr *baseAddrPtr);
  919.     OSErr GDGetPageCnt(GDHandle device,short mode,short *pagesPtr);
  920.     OSErr GDGrayPage(GDHandle device,short page);
  921.     Boolean GDHasMode(GDHandle device,short mode,short *pixelSizePtr,short *pagesPtr);
  922.     short GDModePixelSize(GDHandle device,short mode);
  923.     unsigned char *GDName(GDHandle device);
  924.     char *GDNameStr(GDHandle device);
  925.     ColorSpec *GDNewLinearColorTable(GDHandle device);
  926.     short GDPixelSize(GDHandle device);
  927.     OSErr GDPrintGammaTable(FILE *o,GDHandle device);
  928.     OSErr GDReset(GDHandle device,short *modePtr,short *pagePtr,Ptr *baseAddrPtr);
  929.     OSErr GDRestoreDeviceClut(GDHandle device);
  930.     OSErr GDRestoreGamma(GDHandle device);
  931.     OSErr GDSaveGamma(GDHandle device);
  932.     OSErr GDSetDefaultMode(GDHandle device,short mode);
  933.     OSErr GDSetDelay(GDHandle device,Boolean dontWaitForVBL,double nanoseconds);
  934.     OSErr GDSetEntries(GDHandle device,short start,short count,ColorSpec *aTable);
  935.     OSErr GDSetEntriesByType(GDHandle device,short start,short count,ColorSpec *table);
  936.     OSErr GDSetEntriesByTypeHighPriority(GDHandle device,short start,short count
  937.         ,ColorSpec *table);
  938.     OSErr GDSetGamma(GDHandle device,GammaTbl *myGammaTblPtr);
  939.     OSErr GDSetGray(GDHandle device,Boolean flag);
  940.     OSErr GDSetInterrupt(GDHandle device,Boolean flag);
  941.     OSErr GDSetMode(GDHandle device,short mode,short page,Ptr *baseAddrPtr);
  942.     OSErr GDSetPageDrawn(GDHandle device,short page);
  943.     OSErr GDSetPageShown(GDHandle device,short page);
  944.     OSErr GDStatus(int refNum,int csCode,Ptr csParamPtr);
  945.     OSErr GDSwitchMode(GDHandle device,short mode,long displayModeID,short page,Ptr *baseAddrPtr);
  946.     short GDType(GDHandle device);
  947.     OSErr GDUncorrectedGamma(GDHandle device);
  948.     int GDVersion(GDHandle device);
  949.     int PatchMacIIciVideoDriver(void);
  950.     Boolean IsPCIMac(void);
  951.     void GDRestoreBlackAndWhite(GDHandle device);
  952.     
  953.     /* GetClicks.c */
  954.     
  955.     short    GetClicks(void);
  956.  
  957.     /* GetScreenDevice.c */
  958.     
  959.     GDHandle    GetScreenDevice(int n);
  960.     int            GetScreenIndex(GDHandle device);
  961.     GDHandle    SlotToScreenDevice(int n);
  962.     GDHandle    GetDeviceByRefNum(int n);
  963.     short int    GetDeviceSlot(GDHandle device);            /* gives nonsense on PCI bus */
  964.     char        *GetDeviceSlotName(GDHandle device);    /* works on NuBus, PCI bus, and no bus */
  965.     GDHandle    GetWindowDevice(WindowPtr theWindow);
  966.     GDHandle    GetRectDevice(Rect *r);
  967.  
  968. #endif
  969.  
  970. /* GetTimeDateString.c */
  971.  
  972. char *GetTimeDateString(time_t t);
  973.  
  974. #if MAC_C
  975.     /* GetVersionString.c */
  976.  
  977.     char *GetVersionString(void);
  978.  
  979.     /* GetVoltage.c */
  980.     
  981.     double    VoltsDuringFrame(double frames);
  982.     double    GetVoltage(short channel,double *gainPtr,double *frequencyPtr,long n
  983.                 ,double *sdPtr);
  984.     short    GetVoltages(short channel,double *gainPtr,double *frequencyPtr,long *nPtr
  985.                 ,unsigned short readings[],double *voltDeltaPtr,double *voltZeroPtr);
  986.     short    InitiateVoltageSampling(short channel,double *gainPtr,double *frequencyPtr
  987.                 ,double *voltDeltaPtr,double *voltZeroPtr);
  988.     short    RetrieveVoltages(long *nPtr,unsigned short readings[]);
  989.     int        ForeRunnerSlot(void);
  990.     enum{voltageBufferOverflow=1<<0,voltageOverflow=1<<1,voltageUnderflow=1<<2};
  991. #endif
  992.  
  993. /* HexToBinary.c */
  994.  
  995. int HexToBinary(char *string,void *ptr);
  996. char *BinaryToHex(size_t n,void *ptr,char *string);
  997.  
  998. #if MAC_C
  999.     /* HideMenuBar.c */
  1000.     
  1001.     void    HideMenuBar(void);
  1002.     void    ShowMenuBar(void);
  1003.     void SquareCorners(GDHandle device);
  1004.     void RestoreCorners(GDHandle device);
  1005.     void UnclipScreen(GDHandle device);
  1006.     void RestoreScreenClipping(GDHandle device);
  1007.     
  1008.     /* Identify.c */
  1009.     
  1010.     char *IdentifyApplication(void);
  1011.     char *IdentifyCompiler(void);
  1012.     char *IdentifyGreenwichMeanTime(void);
  1013.     char *IdentifyMachine(void);
  1014.     char *IdentifyModel(void);
  1015.     char *IdentifyOwner(void);
  1016.     char *IdentifyVideo(GDHandle device);
  1017.     char *IdentifyVM(void);
  1018.     
  1019.     /* ImageStatistics */
  1020.  
  1021.     double ImageEnergy(GWorldPtr aWorld,Rect *aRect,double background);
  1022.     void ImageStatistics(GWorldPtr world,Rect *rect
  1023.         ,long *minPtr,long *maxPtr,double *meanPtr,double *meanSquarePtr);
  1024.  
  1025.     /* InstallGestaltValue.c */
  1026.  
  1027.     OSErr InstallGestaltValue(OSType selector,long response);
  1028.  
  1029.     /* IsCmdPeriod.c */
  1030.     
  1031.     Boolean IsCmdPeriod(EventRecord *event);
  1032.  
  1033.     /* IsFileSharingOn.c */
  1034.  
  1035.     Boolean IsFileSharingOn(void);
  1036.     OSErr KillFileSharing(void);
  1037.  
  1038. #endif
  1039.  
  1040. /* IsNan.c */
  1041.  
  1042. int IsNan(double x);
  1043. int IsInf(double x);
  1044. #ifndef IsFinite    /* neither NAN nor ±INF */
  1045.     #define IsFinite(x) \
  1046.     (sizeof(x)>8?    \
  1047.     ((*(short *)&(x) & 0x7FFF)!=0x7FFF)        /* 10 or 12 byte double */\
  1048.     :((*(short *)&(x) & 0x7FF0)!=0x7FF0))    /* 8 byte double */
  1049. #endif
  1050.  
  1051. #if MAC_C
  1052.     /* IsWindow.c */
  1053.     Boolean IsWindow(WindowPtr window);
  1054.  
  1055.     /* kbhit.c */
  1056.     
  1057.     int    kbhit(void);
  1058.     int    getcharUnbuffered(void);
  1059.  
  1060.     /* KillEveryoneButMe.c */
  1061.     
  1062.     OSErr KillEveryoneButMe(void);
  1063. #endif
  1064.  
  1065. /* Log2L.c */
  1066.  
  1067. long Log2L(unsigned long j);
  1068.  
  1069. #if MAC_C
  1070.     
  1071.     /* MaximizeConsoleHeight.c */
  1072.     
  1073.     void MaximizeConsoleHeight(void);
  1074. #endif
  1075.  
  1076. /* Mean.c */
  1077.  
  1078. double Mean(double x[],long n,double *sdPtr);
  1079. double MeanF(float x[],long n,double *sdPtr);
  1080. double MeanB(char x[],long n,double *sdPtr);
  1081. double MeanUB(unsigned char x[],long n,double *sdPtr);
  1082. double MeanW(short x[],long n,double *sdPtr);
  1083. double MeanUW(unsigned short x[],long n,double *sdPtr);
  1084. double MeanL(long x[],long n,double *sdPtr);
  1085. double MeanUL(unsigned long x[],long n,double *sdPtr);
  1086.  
  1087. /* Nan.c */
  1088. extern const short __NAN[];
  1089. #define Nan (*(double *)__NAN)
  1090.  
  1091. #if MAC_C
  1092.     /* NoiseFill.c */
  1093.     
  1094.     int NoiseFill(CWindowPtr window,Rect *r,double dx,double dy,Boolean randomPhase);
  1095.     int NoiseFillBits(PixMap *bits,Rect *r,double dx,double dy,Boolean randomPhase);
  1096.     int MakeNoise1(double dx,double dy,Boolean randomPhase,PixMap *bits);    /* Obsolete */
  1097.     
  1098.     /* NoisePdfFill.c */
  1099.     
  1100.     OSErr NoisePdfFill(GWorldPtr world,Rect *rectPtr
  1101.         ,int pdf,double *meanPtr,double *sdPtr,int min,int max);
  1102.     OSErr NoisePdfAdd(GWorldPtr world,Rect *rectPtr
  1103.         ,int pdf,double *meanPtr,double *sdPtr,int min,int max);
  1104.     enum{kBinaryPdf=0,kBinomialPdf,kGaussianPdf,kUniformPdf};
  1105. #endif
  1106.  
  1107. /* Normal.c */
  1108.  
  1109. double NormalPdf(double x);
  1110. double Normal(double x);
  1111. double InverseNormal(double p);
  1112. double NormalSample(void);
  1113. double Normal2DPdf(double r);
  1114. double Normal2D(double r);
  1115. double InverseNormal2D(double p);
  1116. double Normal2DSample(void);
  1117. double InverseNormal2DPdf(double p);
  1118. void BoundedNormalIntegers(short *distribution,long n,double mean,double sd
  1119.     ,short min,short max);
  1120.  
  1121. /* nrand.c */
  1122.  
  1123. unsigned long nrand(unsigned long n);
  1124.  
  1125. /* OpenDataFiles.c */
  1126.  
  1127. unsigned long OpenDataFiles(FILE **inPtr,FILE **outPtr
  1128.                     ,char *inName,char *outName);
  1129.  
  1130. /* OpenPreferencesFolder.c */
  1131.  
  1132. #if !MAC_C
  1133.     #define OSErr short
  1134. #endif
  1135. OSErr OpenPreferencesFolder(void);
  1136. OSErr ClosePreferencesFolder(void);
  1137. OSErr OpenPreferencesWD(short *wdRefNumPtr);
  1138. #if !MAC_C
  1139.     #undef OSErr
  1140. #endif
  1141.  
  1142. #if MAC_C
  1143.     /*    PixMapToPICT.c */
  1144.  
  1145.     void PixMapToPICT(char *filename,PixMap **pm,Rect *rectPtr
  1146.         ,int pixelSize,ColorTable **cTable);
  1147.  
  1148.     /*    PixMapToPostScript.c */
  1149.     
  1150.     void WindowToEPS(CWindowPtr window,char *filename,Rect *rectPtr
  1151.         ,Rect *pageRectPtr,double cellsPerInch,int grayLevels,float reflectance[256]);
  1152.     void PixMapToEPS(char *filename,PixMap **pm,Rect *rectPtr
  1153.         ,Rect *pageRectPtr,double cellsPerInch,int grayLevels);
  1154.     void PixMapToPostScript(char *filename,PixMap **pm,Rect *rectPtr
  1155.         ,Rect *pageRectPtr,double cellsPerInch,int grayLevels);
  1156.     void AppendToFile(char *filename,char *string);
  1157.     
  1158.     /* PlotXY.c */
  1159.     
  1160.     typedef struct{
  1161.         Boolean continuing;    /* zero to start a new curve */
  1162.         long color;            /* e.g. blackColor, blueColor */
  1163.         short lineWidth;    /* in pixels, zero for none */
  1164.         short symbolWidth;    /* in pixels, zero for none */
  1165.         short dashOffset;    /* in pixels */
  1166.         short dash[5];        /* in pixels. The array is terminated by a zero element */
  1167.         short h,v;            /* reserved for internal use */
  1168.         Fixed pathLengthF;    /* reserved for internal use */
  1169.     } PlotXYStyle;
  1170.     void PlotXY(WindowPtr window,double x,double y,PlotXYStyle *style);
  1171. #endif
  1172.  
  1173. /* PrintfExit.c */
  1174.  
  1175. int PrintfExit(const char *format,...);
  1176. int Printf(const char *format,...);
  1177. char *TranslateEOL(char *string);
  1178.  
  1179. #if MAC_C
  1180.     /* PrintfGWorld.c */
  1181.  
  1182.     void PrintfGWorld(GWorldPtr our);
  1183.     void PrintStringAsBitmap(unsigned char *s);
  1184. #endif
  1185.  
  1186. /* PupilMTF.c */
  1187.  
  1188. double PupilMTF(double cPerDeg,double diameterMm,double wavelengthNm);
  1189.  
  1190. #if MAC_C
  1191.     /* QD32Exists.c */
  1192.     
  1193.     Boolean         QD8Exists(void);
  1194.     Boolean            QD32Exists(void);
  1195.     Boolean            NewPaletteManager(void);
  1196. #endif
  1197.  
  1198. /* randU.c */
  1199.  
  1200. unsigned short    randU(void);
  1201. unsigned long    randUL(void);
  1202. void            srandU(unsigned n);
  1203. void            RandFill(void *address,long bytes);
  1204.  
  1205. /* ReadMATLABFile.c */
  1206.  
  1207. int LoadNamedMatIntoDoubles(FILE *f,const char *name,long *rows,long *cols
  1208.     ,double **real,double **imag);
  1209. int LoadNamedMatIntoShorts(FILE *f,const char *name,long *rows,long *cols
  1210.     ,short **real,short **imag);
  1211. int LoadNextMatIntoDoubles(FILE *f,char *name,long *rows,long *cols
  1212.     ,double **real,double **imag);
  1213. int LoadNextMatIntoShorts(FILE *f,char *name,long *rows,long *cols
  1214.     ,short **real,short **imag);
  1215. int SaveMatDoubles(FILE *f,char *name,long rows,long cols,double *real,double *imag);
  1216. int SaveMatShorts(FILE *f,char *name,long rows,long cols,short *real,short *imag);
  1217.  
  1218. #if MAC_C
  1219.     /* RectToAddress.c */
  1220.     
  1221.     unsigned char *RectToAddress(PixMap *pixMapPtr,Rect *rectPtr,short *rowBytesPtr, 
  1222.         short *pixelSizePtr,short *bitsOffsetPtr);
  1223.     Ptr GetPixBaseAddr32(PixMap **pm);
  1224. #endif
  1225.     
  1226. /*    Require.c    */
  1227.  
  1228. void Require(long quickDrawVersion);
  1229. struct PrecompileSizeofInt{
  1230.     int i;
  1231. };
  1232. struct PrecompileSizeofDouble{
  1233.     double d;
  1234. };
  1235.  
  1236. #if MAC_C
  1237.     /* RestoreCluts.c */
  1238.     
  1239.     void RestoreCluts(void);
  1240.     
  1241.     /* Seconds.c */
  1242.  
  1243.     double Seconds(void);
  1244.     Boolean IsDriverServicesLibAvailable(void);
  1245.  
  1246.     /* SetCrsrState.c */
  1247.  
  1248.     void SetCrsrVis(unsigned char cursorVisible);
  1249.     unsigned char GetCrsrVis(void);
  1250.     short GetCrsrState(void);
  1251.     void SetCrsrState(short val);
  1252.  
  1253.     /*    SetEntriesQuickly.c */
  1254.     
  1255.     OSErr SetEntriesQuickly(GDHandle device,short start,short count,ColorSpec *table);
  1256.     short macltset(GDHandle device,register short start
  1257.         ,unsigned short *red,unsigned short *green,unsigned short *blue,short count1);
  1258.     short GetCardType(GDHandle device);
  1259.     char *GetCardBase(GDHandle device);
  1260.     OSErr WaitForNextBlanking(GDHandle device);
  1261.     Boolean SetEntriesQuicklyRecommended(GDHandle device);
  1262.     
  1263.     /* SetFileInfo.c */
  1264.     
  1265.     void    SetFileInfo(char *fileName,OSType fileType,OSType fileCreator);
  1266.     
  1267.     /* SetGestaltValue1.c */
  1268.  
  1269.     OSErr SetGestaltValue1(OSType selector,long response);
  1270.  
  1271.     /* SetMouse.c */
  1272.     
  1273.     void    SetMouse(Point where);
  1274.     
  1275.     /* SetOnePixel.c */
  1276.     
  1277.     void SetPixmapPixel(PixMap *pmHandle,int x,int y,unsigned long value);
  1278.     unsigned long GetPixmapPixel(PixMap *pmHandle,int x,int y);
  1279.     unsigned char *GetPixmapPixelAddress(PixMap *pmHandle,int x,int y);
  1280.     void SetDevicePixel(GDHandle device,int x,int y,unsigned long value);
  1281.     unsigned long GetDevicePixel(GDHandle device,int x,int y);
  1282.     void SetOnePixel(int x,int y,unsigned long value);
  1283.     unsigned long GetOnePixel(int x,int y);
  1284.     #define SetIPixel SetDevicePixel    /*  So that old programs won't break. */
  1285.     #define GetIPixel GetDevicePixel    /*  So that old programs won't break. */
  1286.     
  1287.     /* SetPixelsQuickly.c */
  1288.     
  1289.     int SetPixelsQuickly(int x,int y,unsigned long value[],short n);
  1290.     int GetPixelsQuickly(int x,int y,unsigned long value[],short n);
  1291.     int SetWindowPixelsQuickly(WindowPtr window,int x,int y,unsigned long value[],short n);
  1292.     int GetWindowPixelsQuickly(WindowPtr window,int x,int y,unsigned long value[],short n);
  1293.     int SetDevicePixelsQuickly(GDHandle device,int x,int y,unsigned long value[],short n);
  1294.     int GetDevicePixelsQuickly(GDHandle device,int x,int y,unsigned long value[],short n);
  1295.     int SetPixmapPixelsQuickly(PixMapPtr pmPtr,int x,int y,unsigned long value[],short n);
  1296.     int GetPixmapPixelsQuickly(PixMapPtr pmPtr,int x,int y,unsigned long value[],short n);
  1297.     
  1298.     /* SetPriority.c */
  1299.     
  1300.     void SwapPriority(char *priority);
  1301.     pascal void SetPriority(long i);
  1302.     pascal long GetPriority(void);
  1303. #endif
  1304.  
  1305. /* Shuffle.c */
  1306.  
  1307. void Shuffle(void *array,long elements,size_t elementSize);
  1308.  
  1309. #if MAC_C
  1310.     /* SndPlay1.c */
  1311.     
  1312.     OSErr SndPlay1(Handle snd);
  1313.     void SndStop1(void);
  1314.     short SndDone1(void);
  1315.  
  1316.     /* StringToDateAndSecs.c */
  1317.     
  1318.     double StringToDateAndSecs(char *string,DateTimeRec *date);
  1319.  
  1320.     /* StringBounds.c */
  1321.     
  1322.     void CharBounds(char a,Rect *bounds,long *count);
  1323.     void StrBounds(char *s,Rect *bounds,long *count);
  1324.     double StrOutlineLength(char *s);
  1325.     void StringBounds(const unsigned char *s,Rect *bounds,long *count);
  1326.     double StringOutlineLength(const unsigned char *s);
  1327.  
  1328.     /* Timer.c */
  1329.     
  1330.     struct Timer{
  1331.         TMTask time;
  1332.         long ourA5;
  1333.         long interval,elapsed,elapsedIntervals;
  1334.         long timeToStartTimer;            /*  minimum time in µs */
  1335.         long stopDelay;                    /*  µs from call to stop, re from call to start */
  1336.         long timeManagerVersion;
  1337.         struct Timer *next,*previous;    /*  doubly linked list of Timers */
  1338.     };
  1339.     typedef struct Timer Timer;
  1340.     
  1341.     Timer *NewTimer(void);
  1342.     void DisposeTimer(Timer *t);
  1343.     void StartTimer(Timer *t);
  1344.     long StopTimer(Timer *t);                    /*  µs */
  1345.     double StopTimerSecs(Timer *t);                /*  s */
  1346.     long PeekTimer(Timer *t);                    /*  µs */
  1347.     double PeekTimerSecs(Timer *t);                /*  s */
  1348.     
  1349.     /* TitleBarHeight.c */
  1350.     
  1351.     int TitleBarHeight(WindowPtr window);
  1352.     
  1353.     /* TrapAvailable.c */
  1354.     
  1355.     Boolean    TrapAvailable(short theTrap);
  1356. #endif
  1357.  
  1358. /* Uniform.c */
  1359.  
  1360. double UniformSample(void);
  1361.  
  1362. #if MAC_C
  1363.     /* VBLInstall.c */
  1364.     
  1365.     #if !UNIVERSAL_HEADERS
  1366.         typedef unsigned long UInt32;
  1367.         struct UnsignedWide {
  1368.             UInt32 hi;
  1369.             UInt32 lo;
  1370.         };
  1371.         typedef struct UnsignedWide UnsignedWide, *UnsignedWidePtr;
  1372.         extern pascal void Microseconds(UnsignedWide *microTickCount)={0xA193, 0x225F, 0x22C8, 0x2280};
  1373.     #endif
  1374.     struct VBLTaskAndA5 {
  1375.         volatile VBLTask vbl;
  1376.         long ourA5;
  1377.         #if USESROUTINEDESCRIPTORS || GENERATINGCFM
  1378.             UniversalProcPtr subroutine;
  1379.         #else
  1380.             void (*subroutine)(struct VBLTaskAndA5 *vblData);
  1381.         #endif
  1382.         GDHandle device;
  1383.         long slot;
  1384.         volatile long newFrame;        /* Boolean */
  1385.         volatile long frame;        /* count up from zero */
  1386.         volatile long framesLeft;    /* count down to zero */
  1387.         long framesDesired;
  1388.         UnsignedWide microTicks;    /* Microseconds() at time of most recent VBL */
  1389.         double seconds;                /* Seconds() at time of most recent VBL */
  1390.         void *ptr;                    /* use this for whatever you want */
  1391.     };
  1392.     typedef struct VBLTaskAndA5 VBLTaskAndA5;    
  1393.     OSErr VBLInstall(VBLTaskAndA5 *vblData,GDHandle device,long frames);
  1394.     OSErr VBLRemove(VBLTaskAndA5 *vblData);
  1395.     void SimpleVBLSubroutine(VBLTaskAndA5 *vblData);
  1396.     
  1397.     /* VideoTFB.c */
  1398.     
  1399.     Boolean TFBInSlot(int slot);
  1400.     void    SetUpTFB(int slot);
  1401.     void    RampClutTFB(int slot);
  1402.     void    GrayClutTFB(int slot);
  1403.     void    LoadClutTFB(int slot,unsigned char rgb[256][3]);
  1404.     void    NewBlankingTFB(int slot);
  1405.     void    NewFieldTFB(int slot);
  1406.     int        BlankingTFB(int slot);
  1407.     void    SetDepthTFB(int slot,short int bits);
  1408.     void    SynchSetDepthTFB(int masterSlot,int slot,short int bits);
  1409.     void    SynchToMainDeviceTFB(GDHandle device);
  1410.     void    HaltTFB(int slot);
  1411.     void    RestartTFB(int slot,short int bits);
  1412.     void    HaltDeviceTFB(GDHandle device);
  1413.     void    RestartDeviceTFB(GDHandle device);
  1414.     void    ScrollTFB(int slot,short int bits,long x,long y);
  1415.     void    PanTFB(int slot,long int x);
  1416. #endif
  1417.  
  1418. /* VLambda.c */
  1419.  
  1420. double VLambda(double nm);
  1421. double VLambdaPrime(double nm);
  1422.  
  1423. #if MAC_C
  1424.  
  1425.     /* WaitSeconds.c */
  1426.     
  1427.     void WaitSeconds(double secs);
  1428.  
  1429.     /* Zoom.c */
  1430.     
  1431.     void Zoom(WindowPtr theWindow,int zoomDir,EventRecord *event);
  1432. #endif
  1433.  
  1434. #endif /* _VIDEOTOOLBOX_ */
  1435.